package basicJava.generics.generics3;
/*
 * 下面的程序可以为任何类构造一个Generator，只要该类具有默认的构造器
 * 为了减少类型声明，提供一个泛型方法，用以生成BasicGenerator
 */

import basicJava.generics.generics2.Generator;

public class BasicGenerator<T> implements Generator<T> {
	private Class<T> type;
	public BasicGenerator(Class<T> type){
		this.type = type;
	}
	@Override
	public T next() {
		
	try {
		return type.newInstance();
	} catch (Exception e) {
		throw new RuntimeException();
		}
	}
	
	public static <T> Generator<T> create(Class<T> type){
		return new BasicGenerator<>(type);
	}
	
}
